package com.example.mybatisplusdemo.web.controller;

import com.example.mybatisplusdemo.common.JsonResponse;
import com.example.mybatisplusdemo.mapper.BookingTrackMapper;
import com.example.mybatisplusdemo.model.domain.BookingTrack;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/booking")
@RequiredArgsConstructor
public class BookingStatusController {

    private final BookingTrackMapper bookingTrackMapper;

    /**
            * 查询预订状态
     */
    @GetMapping("/status")
    public JsonResponse<Object> getBookingStatus(
            @RequestParam String trackingId) {
        try {
            BookingTrack track = bookingTrackMapper.selectByTrackingId(trackingId);
            if (track == null) {
                return JsonResponse.failure("找不到预订记录").setCode(404);
            }
            return JsonResponse.success(track, "预订状态查询成功");
        } catch (Exception e) {
            return JsonResponse.failure("查询失败: " + e.getMessage())
                    .setCode(500);
        }
    }
}